require(['./config'],()=>{
    require(['utils','footer'],(utils)=>{
        class Denglu{
            constructor(){
                this.username = document.querySelector('#username').value
                this.password = document.querySelector('#password').value
                this.userList = localStorage.getItem('userList')
                this.button=document.querySelector('#bouttn')
                this.Denglu()
            }
            Denglu(){
                document.querySelector('button').onclick = function () {
                    var username = document.querySelector('#username').value
                    var password = document.querySelector('#password').value
                    var userList = localStorage.getItem('userList')
                    if (userList) {
                        userList = JSON.parse(userList)
                        // 判断userList里是否存在一条数据跟输入的用户名密码相同
                        var isExist = userList.some(user => {
                            return user.username === username && user.password === password
                        })
                        if (isExist) {
                            // 登录成功
                            // TODO:7天免登录
                            // utils.setCookie('loginUser', username)
                            alert('登录成功，即将回到首页')
                            window.open('../')
                        } else {
                            alert('用户名或者密码错误')
                        }
                    } else {
                        // 还没有用户
                        alert('请先注册')
                        location.replace('./zhuce.html')
                    }
                }
            }
        }
        new Denglu
    })
})
